#! /bin/bash
#PBS -N Test_GPU_Wrapper
#PBS -l walltime=02:00:00
#PBS -q class
#PBS -o output/test_gpuWrap.out
#PBS -e output/test_gpuWrap.err
#PBS -d /nethome/jchua3/vetter/cse6220/project/

cd $PBS_O_WORKDIR
echo "*****we are in "
echo $PBS_O_WORKDIR
echo "*****"

#run R on all the nodes we want
`which mpirun` -n 1 -machinefile $PBS_NODEFILE R --vanilla > output/test_gpuWrap_R.out <<EOF

library(gputools)
library(MASS) 

#set working directory of main source path file and source it
setwd("/nethome/jchua3/vetter/cse6220/project/")
source("source.R")

#start up the MPI cluster with np instances of R, running on all
#available nodes
cl <- startCluster($np)

#prepare data
size <- 2000
mu <- mat.or.vec(size,1)
cov <- mat.or.vec(size,size)
diag(cov) <- 1
A <- mvrnorm(size,mu,cov)
B <- mvrnorm(size,mu,cov)
C <- mvrnorm(size,mu,cov)
data <- list(A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B,A,B)

#run GPU matmult and save results
#results <- clusterCall(cl, gpuSvd, A, B)
results <- distTime(taskPullNormal(cl,data,gpuFuncWrap,gpuMatMult,cpuMatMult,nodeMap,C))
save(results, file="output/test_gpuWrap_results.Rdata")

stopCluster()
mpi.quit()


EOF



